home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / wptools1.zip / DEMO / MDI_PRJ / PRINPR.PAS < prev   
Pascal/Delphi Source File  |  1996-04-13  |  6KB  |  175 lines

  1. unit PrinPr;
  2. { This Unit shows how to use buttons and strings in the statusbar
  3.   and how to use the function print_xywh(Canvas, ...
  4.  
  5.   I Use the wpFastPrint Method in this unit:
  6.     1. Call   print_xywh(Canvas, ... , wpFastPrintInit)
  7.     2. Then call  print_xywh(Canvas, ... , wpFastPrint)   so often as you like
  8.     3. Call   print_xywh(Canvas, ... , wpFastPrintExit)
  9.   You shoul NEVER forget to call wpFastPrintExit !
  10.   The FastPrint Method is much faster wich large Text with lots of pages to print
  11.   because initialisation is only done one time.
  12.  
  13.   If you have only short Text ore more time
  14.   then you may call print_xywh(Canvas, ... , wpNormalPrint) and you dont have to worry.
  15.  
  16.   If you want to check if there is enoug space to print all lines you can call
  17.     print_xywh(Canvas, ... , wpPrintCalc). You may do this after wpFastPrintInit, too.
  18. }
  19.  
  20. interface
  21.  
  22. uses
  23.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  24.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, WPRich, WPWinCtr, WPStatus, WPDefs;
  25.  
  26. type
  27.   TPrintPreview = class(TForm)
  28.     WPStatusBar1: TWPStatusBar;
  29.     Panel1: TPanel;
  30.     PaintBox1: TPaintBox;
  31.     procedure FormCreate(Sender: TObject);
  32.     procedure WPStatusBar1Update(Sender: TObject);
  33.     procedure PaintBox1Paint(Sender: TObject);
  34.     procedure WPStatusBar1Selection(Sender: TObject; index: Integer;
  35.       typ: TWPStatusItemCont; name: String; x, y, w: Integer;
  36.       var Button: TMouseButton; var Shift: TShiftState);
  37.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  38.     procedure Resize(Sender: TObject);
  39.   private
  40.     { Private-Deklarationen }
  41.     initialized : Boolean; { wpFastPrintInit called ? }
  42.     Zoom    : Integer;
  43.   public
  44.     { Public-Deklarationen }
  45.     last_line,first_line : Longint;
  46.     WordProcessor : TWPRichText;
  47.   end;
  48.  
  49. var
  50.   PrintPreview: TPrintPreview;
  51.  
  52. implementation
  53.  
  54. {$R *.DFM}
  55.  
  56. procedure TPrintPreview.FormCreate(Sender: TObject);
  57. begin
  58.   WPStatusBar1.SetStringWidthIndex(0,75);
  59.   WPStatusBar1.SetStringWidthIndex(1,75);
  60.   WPStatusBar1.SetStringWidthIndex(1,75);
  61. end;
  62.  
  63. procedure TPrintPreview.WPStatusBar1Update(Sender: TObject);
  64. begin
  65.   WPStatusBar1.SetStringIndex(0,IntToStr(first_line));
  66.   WPStatusBar1.SetStringIndex(0,'');
  67.   WPStatusBar1.SetStringIndex(0,'');
  68. end;
  69.  
  70. procedure TPrintPreview.PaintBox1Paint(Sender: TObject);
  71. begin
  72.    if not initialized then                                     { I Use the FastPrintMethod ! }
  73.    begin WordProcessor.Print_xywh(PaintBox1.Canvas,0,0,
  74.               PaintBox1.Width,PaintBox1.Height, first_line,wpFastPrintInit);
  75.          initialized := TRUE;
  76.    end;
  77.  
  78.    { Set zooming }
  79.    WordProcessor.Zooming := Zoom;
  80.  
  81.    { Options: pmUsePaper,pmWhiteTransparent,
  82.          pmAllTransparent,pmUseBKColor,pmIgnoreZooming,
  83.          pmUsePageBreaks
  84.      all in unit WPWinCtr. }
  85.  
  86.    WordProcessor.Print_XYWH_Mode := [pmUsePageBreaks]; 
  87.    last_line := WordProcessor.Print_xywh(PaintBox1.Canvas,0,0,
  88.           PaintBox1.Width,PaintBox1.Height, first_line,wpFastPrint);
  89.  
  90.    with PaintBox1.Canvas do
  91.    begin
  92.      Pen.Width := 1;
  93.      Pen.Color := clBlack;
  94.      Pen.Style := psDot;
  95.      MoveTo(0,0);
  96.      LineTo(PaintBox1.Width-1,0);
  97.      LineTo(PaintBox1.Width-1,PaintBox1.Height-1);
  98.      LineTo(0,PaintBox1.Height-1);
  99.      LineTo(0,0);
  100.    end;
  101.  
  102.    { The last FALSE means that output shoud be done, not only calculation }
  103. end;
  104.  
  105. procedure TPrintPreview.WPStatusBar1Selection(Sender: TObject;
  106.   index: Integer; typ: TWPStatusItemCont; name: String; x, y, w: Integer;
  107.   var Button: TMouseButton; var Shift: TShiftState);
  108. begin
  109.    if index=3 then Close { selected END }
  110.    else if index=2 then   { selected NEXT }
  111.    begin
  112.           first_line := last_line;
  113.           PaintBox1.invalidate;
  114.           WPStatusBar1.SetStringIndex(0,IntToStr(first_line));
  115.    end;
  116. end;
  117.  
  118. procedure TPrintPreview.FormClose(Sender: TObject;
  119.   var Action: TCloseAction);
  120. begin
  121.    if initialized then                                     { Never forget to call Exit !  }
  122.    begin WordProcessor.Zooming := 100;
  123.          WordProcessor.Print_xywh(PaintBox1.Canvas,0,0,
  124.               PaintBox1.Width,PaintBox1.Height, first_line,wpFastPrintExit);
  125.          initialized := TRUE;
  126.    end;
  127. end;
  128.  
  129. procedure TPrintPreview.Resize(Sender: TObject);
  130. var
  131.   xm, ym : Real;
  132.   papxsiz, papysiz,lmarg,tmarg : Longint;
  133.   x,y,w,h : Integer;
  134. begin
  135.   papxsiz := (WordProcessor.Memo.Header.Layout.paperw *
  136.         Screen.PixelsPerInch) div 1440;
  137.   papysiz := (WordProcessor.Memo.Header.Layout.paperh *
  138.         Screen.PixelsPerInch) div 1440;
  139.   xm := Width / papxsiz;
  140.   ym := (Height-WPStatusBar1.Height-50) /  papysiz;
  141.   if xm < ym then ym := xm;
  142.  
  143.   w := round(papxsiz * ym);
  144.   H := round(papysiz * ym);
  145.  
  146.   x := (Width - Panel1.Width) div 2;
  147.   y  := (Height -(WPStatusBar1.Height + h + 10)) div 2;
  148.  
  149.   Panel1.SetBounds(x,y,w,h);
  150.  
  151.   lmarg := (WordProcessor.Memo.Header.Layout.margl *
  152.         Screen.PixelsPerInch) div 1440;
  153.   tmarg := (WordProcessor.Memo.Header.Layout.margt *
  154.         Screen.PixelsPerInch) div 1440;
  155.  
  156.   y := round(tmarg*ym);
  157.   x := round(lmarg*ym);
  158.   lmarg := (WordProcessor.Memo.Header.Layout.margr *
  159.         Screen.PixelsPerInch) div 1440;
  160.   tmarg := (WordProcessor.Memo.Header.Layout.margb *
  161.         Screen.PixelsPerInch) div 1440;
  162.  
  163.   w :=  w - x - round(lmarg*ym);   { w= Panel1.Width }
  164.   h :=  h - y - round(tmarg*ym);   { h= Panel1.Height }
  165.  
  166.   PaintBox1.SetBounds(x,y,w,h);
  167.  
  168.   if not Panel1.Visible then Panel1.Visible:= TRUE;
  169.   Zoom := round(100 * ym);
  170.  
  171.   WPStatusBar1.SetString(stStatus,IntToStr(Zoom)+'%');
  172. end;
  173.  
  174. end.
  175.